package at.jku.se.fastsell.resource;

import java.util.List;

import javax.ejb.Stateless;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import at.jku.se.fastsell.data.Auction;
import at.jku.se.fastsell.data.DataAccess;
import at.jku.se.fastsell.db4o.DatabaseException;

@ApplicationPath("/")
@Path("/auction")
@Stateless
public class AuctionsResource {

	
	
	@GET
	@Path("/{auctionid}")
	@Produces(MediaType.APPLICATION_JSON)
	public Auction getArticle(@PathParam("auctionid") String auctionId) {
		long auctionId2 = new Long(auctionId);
		List<Auction> auctions = DataAccess.getAllAuctions();
		for (Auction auction : auctions) {
//			if (auctionId2 == auction.getAuctionID()) {
				return auction;
//			} 
		}
		Auction nix = new Auction();
		nix.setTitle("dont find the fuckin auction");
		return nix;
	}
	
	@PUT
	@Path("/sampleData")
	public void createSampleAcutions() throws DatabaseException {
		DataAccess.fillWithSampleData();
	}
	
	@PUT
	@Path("/clean")
	public void deleteSampleData() throws DatabaseException {
		DataAccess.clearDatabase();
	}
	
}
